<?
$path = "/www/resellers_advanced/login/languages";


$pg = pg_connect("host=verdi1.bastun.net dbname=rp2 user=root password=w9JwRoA");

function obhod($dir, $lang, $basepath = "rp_") {
   $d = opendir($dir);
//   echo "dir: $dir<BR>";
   while ($path = readdir($d)) {
      if ($path == ".." || $path == ".") continue;
      unset($_LANG);

      if (is_dir($dir . '/' . $path)) {
         obhod($dir . '/' . $path, $lang, $basepath . '/' . $path);
      } else {
         include($dir . '/' . $path);
         $category = ereg_replace('//', '', ereg_replace("^rp_/", "rp_", "$basepath/$path"));
         foreach ($_LANG as $key=>$value) {
            $sql = "INSERT INTO languages (language, category, msg_id, msg) VALUES('$lang', '$category', '$key', '$value')";
            print "sql: $sql\n";
            //pg_query($sql);
         }
      }  
  }
}

$dir = opendir($path);

while ($lang = readdir($dir)) {
//   echo "path: $path\n";
   if ($lang == "." || $lang == ".." || !is_dir($path . '/' . $lang)) continue;
//   echo "path: $path/$lang\n";
//   die('test');
   obhod($path . '/' . $lang, $lang); //path e language   
}

pg_close($pg);
